package com.tjp.eight.ui.fragment.mywallet.wx;

import com.tjp.eight.AllRetrofit;
import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;
import com.tjp.eight.utils.AppUtils;

import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/3/28.
 */
public class WXPresenter extends BasePresenterImpl<WXView> {
    private WXTService service = AllRetrofit.getRetrofit(UrlConstant.BaseUrl).create(WXTService.class);

    public WXPresenter(WXView view) {
        attachView(view);
    }

    public void toWx(String pJson) {
        RequestBody req = AppUtils.getRequestBody(pJson);
        addSubscription(service.ttowx(req), new SubscribeCallBack<>(new NetCallBack<TSResultModel>() {
            @Override
            public void onSuccess(TSResultModel model) {
                view.tSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.fail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void load(String lpJson) {
        RequestBody body = AppUtils.getRequestBody(lpJson);
        addSubscription(service.load(body), new SubscribeCallBack<>(new NetCallBack<TWXRModel>() {
            @Override
            public void onSuccess(TWXRModel model) {
                view.loadSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {

            }

            @Override
            public void onCompleted() {

            }
        }));
    }
}
